sysroot: Add ostree_sysroot_prepare_cleanup()
authorMatthew Barnes <mbarnes@redhat.com>
Wed, 9 Sep 2015 18:50:14 +0000 (14:50 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Wed, 16 Sep 2015 13:23:37 +0000 (09:23 -0400)
New public function works like ostree_sysroot_cleanup() EXCEPT FOR
pruning the repository.

Under the hood, add _ostree_sysroot_piecemeal_cleanup() which takes
flags to better control what files are cleaned up.  Both public cleanup
functions are now wrappers for _ostree_sysroot_piecemeal_cleanup() with
different flags.

doc/ostree-sections.txt
src/libostree/ostree-sysroot-cleanup.c
src/libostree/ostree-sysroot-deploy.c
src/libostree/ostree-sysroot-private.h
src/libostree/ostree-sysroot.h

index a4d4f2e9bdcefcc2856e2b70ad9995b0fc246c88..84ba417e23cb0801b5816af77ecb55a8fb2b1fae 100644 (file)
@@ -386,6 +386,7 @@ ostree_sysroot_get_booted_deployment
 ostree_sysroot_get_deployment_directory
 ostree_sysroot_get_deployment_origin_path
 ostree_sysroot_cleanup
+ostree_sysroot_prepare_cleanup
 ostree_sysroot_get_repo
 ostree_sysroot_deployment_set_kargs
 ostree_sysroot_write_deployments
index 14a3a5e43fd459c3c09d60c4c9f54b24656c4bc4..85364cc792380ddf11425973bb99a0d3823351bd 100644 (file)
@@ -425,20 +425,18 @@ cleanup_ref_prefix (OstreeRepo         *repo,
 }
 
 static gboolean
-generate_deployment_refs_and_prune (OstreeSysroot       *self,
-                                    OstreeRepo          *repo,
-                                    int                  bootversion,
-                                    int                  subbootversion,
-                                    GPtrArray           *deployments,
-                                    GCancellable        *cancellable,
-                                    GError             **error)
+generate_deployment_refs (OstreeSysroot       *self,
+                          OstreeRepo          *repo,
+                          int                  bootversion,
+                          int                  subbootversion,
+                          GPtrArray           *deployments,
+                          GCancellable        *cancellable,
+                          GError             **error)
 {
   gboolean ret = FALSE;
   int cleanup_bootversion;
   int cleanup_subbootversion;
   guint i;
-  gint n_objects_total, n_objects_pruned;
-  guint64 freed_space;
 
   cleanup_bootversion = (bootversion == 0) ? 1 : 0;
   cleanup_subbootversion = (subbootversion == 0) ? 1 : 0;
@@ -471,10 +469,27 @@ generate_deployment_refs_and_prune (OstreeSysroot       *self,
         goto out;
     }
 
+  ret = TRUE;
+ out:
+  ostree_repo_abort_transaction (repo, cancellable, NULL);
+  return ret;
+}
+
+static gboolean
+prune_repo (OstreeRepo    *repo,
+            GCancellable  *cancellable,
+            GError       **error)
+{
+  gint n_objects_total;
+  gint n_objects_pruned;
+  guint64 freed_space;
+  gboolean ret = FALSE;
+
   if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, 0,
                           &n_objects_total, &n_objects_pruned, &freed_space,
                           cancellable, error))
     goto out;
+
   if (freed_space > 0)
     {
       char *freed_space_str = g_format_size_full (freed_space, 0);
@@ -482,11 +497,11 @@ generate_deployment_refs_and_prune (OstreeSysroot       *self,
     }
 
   ret = TRUE;
- out:
-  ostree_repo_abort_transaction (repo, cancellable, NULL);
+
+out:
   return ret;
 }
-  
+
 /**
  * ostree_sysroot_cleanup:
  * @self: Sysroot
@@ -500,27 +515,78 @@ gboolean
 ostree_sysroot_cleanup (OstreeSysroot       *self,
                         GCancellable        *cancellable,
                         GError             **error)
+{
+  OstreeSysrootCleanupFlags flags;
+
+  /* Do everything. */
+  flags = OSTREE_SYSROOT_CLEANUP_ALL;
+
+  return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
+}
+
+/**
+ * ostree_sysroot_prepare_cleanup:
+ * @self: Sysroot
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Like ostree_sysroot_cleanup() in that it cleans up incomplete deployments
+ * and old boot versions, but does NOT prune the repository.
+ */
+gboolean
+ostree_sysroot_prepare_cleanup (OstreeSysroot  *self,
+                                GCancellable   *cancellable,
+                                GError        **error)
+{
+  OstreeSysrootCleanupFlags flags;
+
+  /* Do everything EXCEPT pruning the repository. */
+  flags = OSTREE_SYSROOT_CLEANUP_ALL & ~OSTREE_SYSROOT_CLEANUP_PRUNE_REPO;
+
+  return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
+}
+
+gboolean
+_ostree_sysroot_piecemeal_cleanup (OstreeSysroot              *self,
+                                   OstreeSysrootCleanupFlags   flags,
+                                   GCancellable               *cancellable,
+                                   GError                    **error)
 {
   gboolean ret = FALSE;
   glnx_unref_object OstreeRepo *repo = NULL;
 
+  g_return_val_if_fail (OSTREE_IS_SYSROOT (self), FALSE);
   g_return_val_if_fail (self->loaded, FALSE);
 
-  if (!cleanup_other_bootversions (self, cancellable, error))
-    goto out;
+  if (flags & OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS)
+    {
+      if (!cleanup_other_bootversions (self, cancellable, error))
+        goto out;
+    }
 
-  if (!cleanup_old_deployments (self, cancellable, error))
-    goto out;
+  if (flags & OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS)
+    {
+      if (!cleanup_old_deployments (self, cancellable, error))
+        goto out;
+    }
 
   if (self->deployments->len > 0)
     {
       if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
         goto out;
 
-      if (!generate_deployment_refs_and_prune (self, repo, self->bootversion,
-                                               self->subbootversion, self->deployments,
-                                               cancellable, error))
+      if (!generate_deployment_refs (self, repo,
+                                     self->bootversion,
+                                     self->subbootversion,
+                                     self->deployments,
+                                     cancellable, error))
         goto out;
+
+      if (flags & OSTREE_SYSROOT_CLEANUP_PRUNE_REPO)
+        {
+          if (!prune_repo (repo, cancellable, error))
+            goto out;
+        }
     }
 
   ret = TRUE;
index da6816ada7e4d81c574933b4839f0a5b26b22dd3..daa864046108e038683b08289d130bf54eb78de8 100644 (file)
@@ -489,6 +489,9 @@ checkout_deployment_tree (OstreeSysroot     *sysroot,
   if (!glnx_opendirat (sysroot->sysroot_fd, osdeploy_path, TRUE, &osdeploy_dfd, error))
     goto out;
 
+  if (!glnx_shutil_rm_rf_at (osdeploy_dfd, checkout_target_name, cancellable, error))
+    goto out;
+
   if (!ostree_repo_checkout_tree_at (repo, &checkout_opts, osdeploy_dfd,
                                      checkout_target_name, csum,
                                      cancellable, error))
index fa7b0866ab1f9d14d290550247f8ef97c06e03ed..0c38e269bdd013e384d6ecb73dd275b7f018d6a9 100644 (file)
@@ -90,4 +90,16 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot     *sysroot,
                                            GCancellable      *cancellable,
                                            GError           **error);
 
+typedef enum {
+  OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
+  OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS  = 1 << 1,
+  OSTREE_SYSROOT_CLEANUP_PRUNE_REPO   = 1 << 2,
+  OSTREE_SYSROOT_CLEANUP_ALL          = 0xffff
+} OstreeSysrootCleanupFlags;
+
+gboolean _ostree_sysroot_piecemeal_cleanup (OstreeSysroot *sysroot,
+                                            OstreeSysrootCleanupFlags flags,
+                                            GCancellable *cancellable,
+                                            GError **error);
+
 G_END_DECLS
index 2fbc23b37cee9ab068911d5643f05a003e513965..88cb759280e8862e77a20052f797c501d21ccd98 100644 (file)
@@ -81,6 +81,10 @@ gboolean ostree_sysroot_cleanup (OstreeSysroot       *self,
                                  GCancellable        *cancellable,
                                  GError             **error);
 
+gboolean ostree_sysroot_prepare_cleanup (OstreeSysroot  *self,
+                                         GCancellable   *cancellable,
+                                         GError        **error);
+
 gboolean ostree_sysroot_write_origin_file (OstreeSysroot         *sysroot,
                                            OstreeDeployment      *deployment,
                                            GKeyFile              *new_origin,